package calculator;

import static org.junit.Assert.*; 
import static org.mockito.Mockito.*;

import java.lang.reflect.InvocationTargetException;

import org.junit.Before;
import org.junit.Test;

public class CalculatorProxyTest {

	private NumberParser parser;
	private Invoker invoker;
	private Calculator calculator;
	private CalculatorProxy proxy;

	@Test
	public void test() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
		
		proxy.calculate("add", "7", "12");
		
		verify(parser).parse("7");
		verify(parser).parse("12");
		
		verify(invoker).go(calculator, "add", new Object[] {7, 12});
		
	}
	
	@Test
	public void substract45() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
		proxy.calculate("substract", "4", "5");
		verify(parser).parse("4");
		verify(parser).parse("5");
		verify(invoker).go(calculator, "substract", new Object[] {4, 5});
	}

	@Before
	public void setUp() {
		parser = mock(IntParser.class
				);
		invoker = mock(Invoker.class);
		calculator = new Calculator();
		proxy = new CalculatorProxy(calculator, invoker, parser);
	}

}
